<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        * {
            margin: 0 auto;
        }
        .father {
            position: relative;
            width: 400px;
            height: 400px;
            background-color: purple;
            text-align: center;
        }
        .son {
            text-align: center;
            background-color: orange;
            width: 200px;
            height: 200px;
        }
        .box {
            width: 300px;
            height: 300px;
            padding: 10px;
            background-color: greenyellow;
        }
    </style>
</head>
<body>
    <div class="father">
        我是有定位父亲
        <div class="son">
            我是儿子
        </div>
    </div>
    <div class="box"></div>
    <script>
        var father = document.querySelector('.father');
        var son = document.querySelector('.son');
        var box = document.querySelector('.box');
        console.log(son.offsetTop);
        console.log(son.offsetLeft);
        console.log(son.offsetParent);
        console.log(box.offsetWidth);//包括边框、内边距、外边距
        console.log(box.offsetHeight);
    </script>
</body>
</html>